<template>
  <view class="index" :class="[nodata ? '' : 'index2']">
    <view class="jtop">
      <view class="status_bar"><!-- 这里是状态栏 --></view>
      <view class="jtop_l" @tap="navigateBack"
        ><image src="../../static/img/ic_back.png"></image
      ></view>
      <!-- <view class="jtop_l" @tap="navigateBack">关闭</view> -->
      <view class="jtop_c">采购计划</view>
      <!-- <view class="jtop_r" @tap="jshow_pop"><image src="../../static/img/doc/ic_add.png"></image></view> -->
    </view>
    <view class="tophr"></view>

    <!-- 无内容 -->
    <view class="no" v-if="!nodata">
      <view class="no_t">
        <image
          src="../../static/img/index/2/ic_procurement plan_grey.png"
        ></image>
      </view>
      <view class="no_c">
        暂无采购计划
      </view>
      <view class="no_f" @tap="jshow_pop">
        新建采购计划
      </view>
    </view>

    <view v-if="nodata">
      <view
        class="wl"
        @tap="logoTime2(item.id)"
        v-for="(item, index) in items"
        :key="item.id"
      >
        <view class="wl_l">
          <view class="wl_lt">
            {{ item.name }}
          </view>
          <view class="wl_lf">
            总计：{{ item.totalAmount }} {{ item.unit }}
          </view>
        </view>
        <view class="wl_r">
          <view class="wl_rt">
            {{ item.lastUpdateTime }}
          </view>
        </view>

        <image src="../../static/img/jt.png" class="blb_r"></image>
      </view>

      <image
        src="../../static/img/index/5/xx2.png"
        class="xx2"
        @click="jshow_pop"
      ></image>
    </view>

    <!-- 弹出层 -->
    <view :class="[ashowpop2 ? 'tc' : 'tc hide']">
      <view class="jtop_bj" @click="btTCC"></view>

      <view class="tc_fbox">
        <!-- <view class="tc_fbox_bt3" @click="btTC_bj">
					编辑
				</view> -->
        <view class="tc_fbox_bt2" @click="btTC_jdel">
          删除
        </view>
        <view class="tc_fbox_bt" @click="btTCC">
          取消
        </view>
      </view>
    </view>

    <view class="footerhr"></view>

    <view class="jfooter">
      <view class="jfooter_b active">
        <image
          src="../../static/img/index/new/shopping2.png"
          class="jfooter_i"
        ></image>
        <view class="jfooter_t">采购计划</view>
      </view>
      <view class="jfooter_b " @tap="jf01">
        <image
          src="../../static/img/index/new/Partition_fill.png"
          class="jfooter_i"
        ></image>
        <view class="jfooter_t">进度计划</view>
      </view>
      <!-- <view class="jfooter_b" @tap="jf02">
				<image src="../../static/img/index/new/calendar.png" class="jfooter_i"></image>
				<view class="jfooter_t">日常计划</view>
			</view>
			 -->
      <!-- <view class="jfooter_b" @tap="jf04">
				<image src="../../static/img/index/new/solution.png" class="jfooter_i"></image>
				<view class="jfooter_t">领用计划</view>
			</view> -->
    </view>
  </view>
</template>

<script>
import request from '@/common/request.js';
import { mapState } from 'vuex';

export default {
  data() {
    return {
      repeat_click: true,
      ashowpop: false,
      ashowpop_jrename: false,
      ashowpop_jdel: false,
      ashowpopT: false,
      bj: false,
      yd: false,
      nodata: true,
      items: [],
      jqeditid: '',
      ashowpop2: false,
      projectId: uni.getStorageSync('dqfull_name').id,
    };
  },

  onShow() {
    this.lb();
  },

  methods: {
    btTC_bj() {
      var jc = this.items.filter(item => {
        return item.id == this.jqeditid;
      });

      console.log(jc);

      uni.setStorageSync('jc', jc[0]);

      uni.navigateTo({
        url: '../main/work_c_edit',
      });
    },
    logoTime2(e) {
      console.log(e);
      this.jqeditid = e;
      // this.ashowpop2 = true;

      var jc = this.items.filter(item => {
        return item.id == this.jqeditid;
      });

      console.log(jc);

      uni.setStorageSync('jc', jc[0]);

      uni.navigateTo({
        url: '../main/work_c_more',
      });
    },

    logoTime(e) {
      console.log(e);
      this.jqeditid = e;
      this.ashowpop2 = true;
    },

    btTC_jdel() {
      var aa = this.jqeditid;
      request({
        url: `/modor/v1/project/${this.projectId}/purchase/plan/${aa}`,
        method: 'DELETE',

        success: res => {
          if (res.data.success == true) {
            this.lb();
            this.ashowpop2 = false;
            wx.showToast({
              title: '删除成功',
              icon: 'none',
              duration: 1500,
              success: function() {
                setTimeout(function() {
                  //   uni.navigateTo({
                  // url: '../user/tream',
                  //   });
                }, 1500);
              },
            });
          } else {
            // 错误
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },

    btTCC(e) {
      this.ashowpop2 = !this.ashowpop2;
    },

    lb(e) {
      // 获取列表信息
      request({
        url: `/biz/plan/list`,
        method: 'GET',
        data: {
          page: 1,
          size: 1000,
        },

        success: res => {
          console.log('项目dd列表', res);
          console.log(res.data.data);
          if (res.data.success == true) {
            if (res.data.data) {
              this.items = res.data.data;
              console.log(this.items);
              this.nodata = true;
            } else {
              this.items = '';
              this.dqfull_name = '';
              this.nodata = false;
            }
          } else {
            this.repeat_click = true;
            uni.showToast({
              title: res.data.msg,
              icon: 'none',
            });
          }
        },
        fail: () => {
          this.repeat_click = true;
          uni.showToast({
            title: '服务器开小差，请稍后~',
            icon: 'none',
          });
          return false;
        },
      });
    },

    jf01() {
      uni.navigateTo({
        url: '../main/work_c',
      });
    },
    jf02() {
      uni.navigateTo({
        url: '../main/work_r',
      });
    },
    jf03() {
      uni.navigateTo({
        url: '../main/work_c',
      });
    },
    jf04() {
      uni.navigateTo({
        url: '../main/work_l',
      });
    },
    // 跳转
    jshow_pop() {
      uni.navigateTo({
        url: '../main/work_c_add',
      });
    },
    btTC2() {
      uni.navigateTo({
        url: '../main/work_add',
      });
    },

    navigateBack() {
      uni.switchTab({
        url: 'main',
      });
    },
  },
  computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
};
</script>

<style>
.tophr {
  width: 100%;
  height: 88rpx;
}
.uni-searchbar {
  box-shadow: none;
}

.wl {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  border-bottom: 1px solid #dddddd;
}
.wl_l {
  width: 400rpx;
  height: auto;
  display: block;
  float: left;
  margin: 18rpx 0 18rpx 30rpx;
}
.wl_lt {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  color: #000000;
  font-size: 34rpx;
  line-height: 42rpx;
  margin: 0rpx 0;
}
.wl_lf {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  color: #999999;
  font-size: 24rpx;
  line-height: 32rpx;
  margin: 10rpx 0 0;
}
.wl_r {
  width: 260rpx;
  height: auto;
  display: block;
  float: right;
  margin: 18rpx 30rpx 0 0;
}
.wl_rt {
  width: auto;
  height: auto;
  display: block;
  float: right;
  margin-left: 0;
  color: #cccccc;
  font-size: 24rpx;
  line-height: 42rpx;
  margin-right: 30rpx;
}
.wl_rr {
  width: 16rpx;
  height: 25rpx;
  display: block;
  float: right;
  margin: 6rpx 0 0 20rpx;
}

.doc_bs {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
}
.doc_b {
  width: 720rpx;
  height: auto;
  display: block;
  float: left;
  background: #ffffff;
  border-bottom: 1px solid #dddddd;
  margin: 0 0 0 30rpx;
}
/* .doc_bs .doc_b:last-child{ border: 0;} */
.doc_bl {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 36rpx 30rpx 36rpx 0;
}
.doc_bt {
  width: auto;
  height: 42rpx;
  line-height: 42rpx;
  font-size: 34rpx;
  display: block;
  float: left;
  color: #000000;
  margin: 37rpx 0 0 0;
}
.doc_br {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 32rpx 30rpx 32rpx 0;
}
.doc_b2 {
  width: 600rpx;
  height: auto;
  display: block;
  float: left;
}
.doc_b2t {
  width: 600rpx;
  height: auto;
  font-size: 34rpx;
  line-height: 42rpx;
  color: #000000;
  margin: 18rpx 0 10rpx;
  display: block;
  float: left;
}
.doc_b2f {
  width: 600rpx;
  height: auto;
  font-size: 24rpx;
  line-height: 32rpx;
  color: #fc9422;
  margin: 0rpx 0 rpx;
  display: block;
  float: left;
}

.no {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 400rpx 0 0;
}
.no_t {
  width: 200rpx;
  height: 200rpx;
  display: block;
  float: left;
  margin: 0 275rpx;
  background: #ffffff;
  border-radius: 200rpx;
}
.no_t image {
  width: 140rpx;
  height: 140rpx;
  display: block;
  float: left;
  margin: 30rpx;
}
.no_c {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  margin: 30rpx 0 50rpx;
  color: #666666;
  font-size: 32rpx;
  line-height: 40rpx;
  text-align: center;
}
.no_f {
  width: 460rpx;
  height: 94rpx;
  line-height: 94rpx;
  background: #256aff;
  border-radius: 10rpx;
  display: block;
  float: left;
  margin: 0 145rpx;
  color: #ffffff;
  font-size: 36rpx;
  text-align: center;
}
.no_f:active {
  background: linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.199437),
      rgba(0, 0, 0, 0.199437)
    ),
    #256aff;
}

image.blb_r {
  width: 16rpx;
  height: 25rpx;
  display: block;
  float: right;
  margin: -10rpx 30rpx 0 0rpx;
}

.xx2 {
  width: 180rpx;
  height: 180rpx;
  display: block;
  float: left;
  position: fixed;
  right: 20rpx;
  bottom: 100rpx;
  z-index: 9999;
}
.index {
  background: #ffffff;
  width: 100%;
  height: auto;
}
.jtop {
  width: 100%;
  height: 88rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  box-shadow: inset 0px -1px 0px #dddddd;
}
.jtop_l {
  width: auto;
  height: 88rpx;
  display: block;
  float: left;
  font-size: 32rpx;
  color: #000000;
  line-height: 88rpx;
  margin: 0 0 0 30rpx;
}
.jtop_l image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
  margin: 20rpx 0 20rpx 0;
}
.jtop_lt {
  margin: 0 0 0 10rpx;
}
.jtop_r {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: right;
  margin: 20rpx 20rpx 0 0;
}
.jtop_rl {
  margin: 20rpx 30rpx 0 0;
}
.jtop_r image {
  width: 48rpx;
  height: 48rpx;
  display: block;
  float: left;
}
.jtop_c {
  width: 70%;
  height: 48rpx;
  line-height: 48rpx;
  display: block;
  float: left;
  position: fixed;
  top: 20rpx;
  left: 15%;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
}
.jtop_c image {
  width: 36rpx;
  height: 36rpx;
  display: inline-block;
  float: none;
  margin-bottom: -5rpx;
  margin-left: 5rpx;
}
.jtop_b {
  width: 100%;
  height: auto;
  background: #ffffff;
  position: fixed;
  top: 88rpx;
  left: 0;
  z-index: 1001;
}

.doc_b22 {
  opacity: 0.5;
}

.nd {
  width: 735rpx;
  height: auto;
  display: block;
  float: left;
  margin: 0 0 0 0rpx;
}
.nd_bt {
  width: auto;
  height: 48rpx;
  display: block;
  float: right;
  border: 1px solid #dddddd;
  border-radius: 24rpx;
  margin: 40rpx 0 40rpx 30rpx;
}
.nd_bt text {
  width: auto;
  height: 48rpx;
  display: block;
  float: left;
  margin: 0 7rpx 0 18rpx;
  line-height: 48rpx;
  color: #666666;
  font-size: 24rpx;
}
.nd_bt image {
  width: 13rpx;
  height: 8rpx;
  display: block;
  float: left;
  margin: 21rpx 14rpx 0 0;
}

.tc {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
  display: block;
}
.jtop_bj {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
}
.tc_fbox_bt {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-top: 20rpx solid #f2f2f2;
  background: #ffffff;
}
.tc_fbox {
  width: 100%;
  height: auto;
  display: block;
  float: left;
  background: #f2f2f2;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 10001;
}
.tc_fbox_bt2 {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-top: 0rpx solid #f2f2f2;
  background: #ffffff;
}
.tc_fbox_bt3 {
  width: 100%;
  height: 90rpx;
  line-height: 90rpx;
  display: block;
  float: left;
  text-align: center;
  font-size: 36rpx;
  color: #000000;
  border-bottom: 1px solid #dddddd;
  background: #ffffff;
}

.index2 {
  background: #f2f2f2;
  width: 100%;
  height: auto;
}
</style>
